package com.czxy.demo04;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by hp on 2020/1/31.
 */
public class Test17 {
    public static void main(String[] args) {
        Student s1=new Student("zhangsan",18,"男");
        Student s2=new Student("lihong",22,"女");
        Student s3=new Student("wangwu",19,"男");
        Student s4=new Student("wuwu",8,"女");
        Student s5=new Student("lilin",35,"男");

        List<Student> list=new ArrayList<Student>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);

        int countman = 0;
        int countwoman = 0;
        for (Student stu : list) {
            if (stu.getSex().equals("男")){
                countman++;
            }
            if (stu.getSex().equals("女")){
                countwoman++;
            }
        }
        System.out.println("男("+countman+") 女("+countwoman+")");

        Map<String,Integer> map = new HashMap<>();
        int count = 0;
        for (Student stu : list) {
            if (stu.getAge()>=18){
                count++;
            }
        }
        map.put("成年",count);
        map.put("未成年",list.size()-count);
        for (String s : map.keySet()) {
            System.out.println(s+"人数"+map.get(s));
        }
    }
}
